#include "Teacher.h"

//默认构造
Teacher::Teacher()
{
    
}

//有参构造
Teacher::Teacher(int empId, string name, string password)
{
    //初始化属性
    this->empId = empId;
    this->name = name;
    this->password = password;
}

//菜单界面
void Teacher::openMenu()
{
    cout << "欢迎学生代表：" << this->name << " 登录！" << endl;
    cout << "\t\t------------------------" << endl;
    cout << "\t\t|                      |" << endl;
    cout << "\t\t|     1、查看所有预约  |" << endl;
    cout << "\t\t|                      |" << endl;
    cout << "\t\t|     2、审核预约      |" << endl;
    cout << "\t\t|                      |" << endl;
    cout << "\t\t|     0、注销登录      |" << endl;
    cout << "\t\t|                      |" << endl;
    cout << "\t\t------------------------" << endl;
}

//查看所有预约
void Teacher::showAllOrder()
{
    OrderFile of;
    if (of.size == 0)
    {
        cout << "无预约记录" << endl;
        return;
    }

    for (int i = 0;i < of.size;i++)
    {
        cout << i + 1 << "、";
        cout << "预约日期：周" << of.orderData[i]["date"] << " "
            << "时间段：" << (of.orderData[i]["interval"] == "1" ? "上午" : "下午") << " "
            << "学号：" << of.orderData[i]["stuId"] << " "
            << "姓名：" << of.orderData[i]["stuName"] << " "
            << "机房号：" << of.orderData[i]["roomId"] << " ";

        string status = "状态：";
        //1、审核中  2、已预约  -1、预约失败  0、取消预约
        if (of.orderData[i]["status"] == "1")
        {
            status += "审核中";
        }
        else if (of.orderData[i]["status"] == "2")
        {
            status += "预约成功";
        }
        else if (of.orderData[i]["status"] == "-1")
        {
            status += "预约失败，审核未通过";
        }
        else
        {
            status += "预约已取消";
        }

        cout << status << endl;
    }
}

//审核预约
void Teacher::validOrder()
{
    OrderFile of;
    if (of.size == 0)
    {
        cout << "无预约记录" << endl;
        return;
    }

    vector<int>v;
    int index = 1;
    cout << "待审核的预约记录如下：" << endl;
    for (int i = 0;i < of.size;i++)
    {
        if (of.orderData[i]["status"] == "1")
        {
            v.push_back(i);
            
            cout << index++ << "、";
            cout << "预约日期：周" << of.orderData[i]["date"] << " "
                << "时间段：" << (of.orderData[i]["interval"] == "1" ? "上午" : "下午") << " "
                << "学号：" << of.orderData[i]["stuId"] << " "
                << "姓名：" << of.orderData[i]["stuName"] << " "
                << "机房号：" << of.orderData[i]["roomId"] << " ";

            string status = "状态：审核中";
            cout << status << endl;
        }
    }
    cout << "请输入审核的预约记录，0代表返回" << endl;
    int select = 0; //接收用户选择的预约记录
    int ret = 0;    //接收预约结果的记录

    while (true)
    {
        cin >> select;
        if (select >= 0 && select <= v.size())
        {
            if (select == 0)
            {
                break;
            }
            else
            {
                cout << "请输入审核结果：" << endl;
                cout << "1、通过" << endl;
                cout << "2、不通过" << endl;

                cin >> ret;
                if (ret == 1)
                {
                    //通过情况
                    of.orderData[v[select - 1]]["status"] = "2";
                }
                else
                {
                    //不通过的情况
                    of.orderData[v[select - 1]]["status"] = "-1";
                }
                //更新预约记录
                of.updateOrder();

                cout << "审核完毕" << endl;
                break;
            }
        }
        cout << "输入有误，请重新输入：" << endl;
    }
}